#include <iostream>
#include <cstring>
using namespace std;
const int initsize = 20;
//单链表
typedef struct LNode
{
    int data;
    LNode *next;
} LNode, *LinkList;
void init(LinkList &L)
{
    L = (LinkList)malloc(sizeof(LNode)); //申请一个头节点
    L->next = NULL;
}
//返回值不知道该返回什么
LNode *headInsert(LinkList &L, int value)
{
    LNode *s;
    s = (LinkList)malloc(sizeof(LNode));
    s->data = value;
    s->next = L->next, L->next = s;
    return s;
}
void display(LinkList L)
{
    LNode *p = L->next;
    while (p != NULL)
    {
        cout << p->data << " ";
        p = p->next;
    }
    cout << endl;
}
LinkList func(LinkList &L, int n)
{
    LNode *p = L->next, *pre = L, *q;
    bool b[n];
    for (int i = 0; i < n; i++)
        b[i] = false;
    while (p)
    {
        if (!b[abs(p->data)])
        {
            b[abs(p->data)] = true;
            pre = p, p = p->next;
        }
        else
        {
            q = p, pre->next = q->next, p = p->next, free(q);
        }
    }
    return L;
}

int main()
{
    LinkList L;
    init(L);
    for (int i = 0; i < 4; i++)
        for (int j = 0; j < 3; j++)
            if (i != j)
                headInsert(L, i + j);
            else
                headInsert(L, -i - j);
    display(L);
    display(func(L, 10));
    return 0;
}